$(function(){
  $('.frm').hide();
  $('#dg').datagrid({url:"/cliente/buscarPedidosRecentes", onClickRow:function(rowIndex, rowData){
    dados = {cod_pedido:rowData.id_pedido};
    Rk.service('cliente','verPedido',dados,function(ret){
      $('.dgr').hide();
      $('.frm').html(ret.html).show();
      $('.btn.back').click(function(){$('.frm').hide();$('.dgr').show();$('#dg').datagrid('unselectAll');});
    });
  },onLoadSuccess:function(data){
    if(!data.total){
      $('.dgr').hide();
      $('.emptyset').show();
    }
  }});
});


function formataMoeda(val,row){  
    if(val!=null){
    nStr = val + '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? ',' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
      x1 = x1.replace(rgx, '$1' + '.' + '$2');
    }
    val =  x1 + x2;
    return "R$ " + val;}
}

function formataData(val, row){
  if(val!=null){
  nStr = val + '';
  x = nStr.split('-');
  y = x[2].split(' ');
  return y[0] + '/' + x[1] + '/' + x[0] + ' ' + y[1];
  }
}
